package learnMethod

import (
	"errors"
	"fmt"
)

func ErrorTest() {
	//defer达到压入栈 最后运行  配合recover()捕获到异常
	defer func() {
		err := recover()
		if err != nil {
			fmt.Println("err=", err)
		}
	}()
	one := 10
	two := 0
	res := one / two
	//下面这种捕获不到异常
	//res := 10 / 0
	fmt.Println(res)
}

func ErrorTest02(one int) error {
	if one == 1 {
		return nil
	} else {
		return errors.New("出错啦")
	}
}
